package ch.sfug.data {

	/**
	 * @author mich
	 */
	public class Set {
		
		private var data:Array;

		public function Set() {
			data = new Array();
		}

		public function isEmpty():Boolean {
			return data.length == 0;
		}

		public function contains( o:Object ):Boolean {
			for each( var obj:Object in data ) {
				if( obj == o ) return true;
			}
			return false;
		}


		public function add( obj:Object ):Boolean {
			if( !contains( obj ) ) {
				data.push( obj );
				return true;
			} else {
				return false;
			}
		}
		
		public function remove( obj:Object ):Boolean {
			for( var i:uint = 0; i < data.length; i++ ) {
				if( obj == data[ i ] ) {
					data.splice( i, 1 );
					return true;
				}
			}
			return false;
		}

		public function get length():Number {
			return data.length;
		}

		public function toArray():Array {
			return data.slice();
		}
	}
}
